export default {
  namespaced: true,
  state: {
    name: "名字aaaa",
    products: [],
  },
  mutations: {
    //获取残品数据
    SET_PRODUCT(state, payload) {
      state.products = payload;
      // console.log(payload)
      console.log(state.products);
    },
    // 库存减少
    DECREASE_INVENTORY(state,payload){
      let target=state.products.find(item=>item.id===payload.id)
      if(target){
         target.inventory--
                }
      },
      // 库存增加 
      INCREASE_INVENTORY(state,payload){
        let target=state.products.find(item=>item.id===payload.id)
        if(target){
           target.inventory++
                  }
        },
      },
  
  actions: {
    async FETCH_PRODUCT(context) {
      const res = await fetch("http://chst.vip/data/index.json").then((body) =>
        body.json()
      );
      context.commit("SET_PRODUCT", res.data);
    },
  },
  
  }